********************************
***Summary Statistics***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==0  {
cap cd "E:\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
} 

use 3_clean_data, replace

*********************************
***BALANCE/DEMOGRAPHY TABLE: Create Variables and Format***
*********************************
gen topissue_immigration=topissue_type==1

global covarsum female white black hispanic asian ///
	a_18_24 a_25_34 a_35_44 a_45_64 a_65 northeast midwest south west ///
	collegeorhigher fulltimeemployed ///
	week_facebook week_twitter week_tv week_newspaper week_fox week_msnbc ///
	independent rhigh voted trump2016 trumpfan obamafan ///
	topissue_immigration pre_increase pre_decrease

label variable female 				"Female"
label variable white 				"White"
label variable black				"Black"
label variable hispanic				"Hispanic"
label variable asian				"Asian"
label variable a_18_24				"18-24 years"
label variable a_25_34				"25-34 years"
label variable a_35_44				"35-44 years"
label variable a_45_64				"45-64 years"
label variable a_65					"65+ years"
label variable collegeorhigher		"College or More"
label variable fulltime				"Full-time Employed"
label variable northeast			"Northeast"
label variable midwest				"Midwest"
label variable south				"South"
label variable west					"West"
label variable week_facebook		"News (Weekly+): Facebook"
label variable week_twitter			"News (Weekly+): Twitter"
label variable week_newspaper		"News (Weekly+): Newspaper"
label variable week_tv				"News (Weekly+): TV"
label variable week_fox				"News (Weekly+): FOX News"
label variable week_msnbc			"News (Weekly+): MSNBC"
label variable independent			"Party: Independent"
label variable rhigh				"Polarized (Estimated)"
label variable voted				"Voted (2016)"
label variable trump2016			"Voted for Trump (2016)"
label variable trumpfan				"Fan of Trump"
label variable obamafan				"Fan of Obama"
label variable topissue_immigration	"Immigration: Top Issue"
label variable pre_increase			"Immigration: Should Increase"
label variable pre_decrease			"Immigration: Should Decrease"

*****************************
*****************************
*****************************


file close _all
capture macro drop fh
file open fh using "${out}2_SumStatsBalance.tex", write replace
file write fh ///
"\hspace*{-1cm}\small{\begin{tabular}{lccccccccc}"  _n ///
"\toprule" _n ///
" & \multicolumn{4}{c}{\textbf{Republicans}} & & \multicolumn{4}{c}{\textbf{Democrats}} \\ " _n ///
"	& Mean &  S.D. & F-Test 	&  P-Value & &	Mean &	S.D. & 	F-Test 	&  	P-Value  \\" _n ///
"\hline \\" _n 

foreach y in $covarsum	 {
	
	sum `y' if recruit==0
	local br = round(`r(mean)'*1000)/1000
	local br : di %6.3f `br'
	local sr = round(`r(sd)'*1000)/1000
	local sr : di  %6.3f `sr'

	sum `y' if recruit==1
	local bd = round(`r(mean)'*1000)/1000
	local bd : di %6.3f `bd'
	local sd = round(`r(sd)'*1000)/1000
	local sd : di  %6.3f `sd'
	
	reg `y' i.treatment if recruit==0

	testparm i.treatment
	local fr = round(`r(F)'*10000)/10000
	local fr : di %6.3f `fr'
	local pr = round(`r(p)'*10000)/10000
	local pr : di  %6.3f `pr'

	reg `y' i.treatment if recruit==1

	testparm i.treatment
	local fd = round(`r(F)'*10000)/10000
	local fd : di %6.3f `fd'
	local pd = round(`r(p)'*10000)/10000
	local pd : di  %6.3f `pd'

	local vlab1: variable label `y'

	file write fh ///
	"`vlab1' & `br'	& (`sr') & `fr' & `pr' & & `bd'	& (`sd') & `fd' & `pd'	\\" _n ///
	"[.1em]" _n	
		
}

count if recruit==0
local rN=r(N)
count if recruit==1
local dN=r(N)

file write fh ///
"&	&	& &	&	\\" _n ///
"N	&	`rN'	&	& & & &	`dN'	&	\\" _n ///
"[.25em]" _n ///
"\bottomrule" _n ///
"\end{tabular}}\hspace*{-1cm}" _n
file close fh



*********************************
*********************************
*********************************
***BASELINE INDEX MEANS: Create Variables and Format***
*********************************


foreach x in pro anti {

gen q1_`x'=post_borderwall_`x'
gen q2_`x'=post_borderpatrol_`x'
gen q3_`x'=post_checkworkerimmstatus_`x'
gen q4_`x'=post_deportall_`x'
gen q5_`x'=post_deportcrimerecord_`x'
gen q6_`x'=post_pathtocitizen_`x'
gen q7_`x'=post_dreamerpathtocitizen_`x'
gen q8_`x'=post_contribdreamer_`x'
gen q9_`x'=post_contribspanish_`x'
gen q10_`x'=post_contribenglish_`x'
gen q11_`x'=post_contriblegal_`x'
gen q12_`x'=post_contribillegal_`x'
gen q13_`x'=post_immlevel_`x'
gen q14_`x'=post_economicimpact_`x'
gen q15_`x'=post_crimeshare_`x'
gen q16_`x'=post_overall_`x'

}

foreach x in pro anti {

label variable q16_`x' "Overall View of Immigrants"
label variable q15_`x' "Immigrant Crime Share"
label variable q14_`x' "Immigrant Economic Impact"
label variable q13_`x' "Ideal Level of Immigration"
label variable q12_`x' "Contribution: Undocumented Immigrants"
label variable q11_`x' "Contribution: Legal Immigrants"
label variable q10_`x' "Contribution: English-speaking Immigrants"
label variable q9_`x' "Contribution: Spanish-speaking Immigrants"
label variable q8_`x' "Contribution: Dreamers"
label variable q7_`x' "Path to Citizenship: Dreamers"
label variable q6_`x' "Path to Citizenship: All Immigrants" 
label variable q5_`x' "Deport Immigrants with Crime Record"
label variable q4_`x' "Deport All Immigrants"
label variable q3_`x' "Check Worker Immigration Status"
label variable q2_`x' "Border Patrol"
label variable q1_`x' "Border Wall"

}

label variable prob_index_pro "Immigration Index"
label variable prob_index_anti "Immigration Index"


 
*****************************
*****************************
*****************************

keep if treatment==0

file close _all
capture macro drop fh
file open fh using "${out}1_SumStatsIndex.tex", write replace
file write fh ///
"\hspace*{-1cm}\small{\begin{tabular}{lccccc}"  _n ///
"\toprule" _n ///
" & \multicolumn{2}{c}{\textbf{Republicans}} & & \multicolumn{2}{c}{\textbf{Democrats}} \\  " ///
" & \multicolumn{2}{c}{\textit{Probability}} & & \multicolumn{2}{c}{\textit{Probability}} \\ [0.75em] " ///
" & \multicolumn{2}{c}{\textit{Anti-Immigrant}} & & \multicolumn{2}{c}{\textit{Pro-Immigrant}} \\ " ///
"\textit{Control Group (No Audio)}	& Mean &  S.D. & &	Mean &	S.D.  \\" _n ///
"\hline \\" _n 

	sum prob_index_anti if recruit==0
	local br = round(`r(mean)'*1000)/1000
	local br : di %6.3f `br'
	local sr = round(`r(sd)'*1000)/1000
	local sr : di  %6.3f `sr'

	sum prob_index_pro if recruit==1
	local bd = round(`r(mean)'*1000)/1000
	local bd : di %6.3f `bd'
	local sd = round(`r(sd)'*1000)/1000
	local sd : di  %6.3f `sd'
	
	local vlab1: variable label prob_index_pro
	
	file write fh ///
	"`vlab1' & `br'	& (`sr')  & & `bd'	& (`sd') 	\\ \\" _n ///
	"\textbf{Components of Index} & &&&& 	\\  [0.5em] " _n 
	
	
foreach y of numlist 16/1	 {
	
	sum q`y'_anti if recruit==0
	local br = round(`r(mean)'*1000)/1000
	local br : di %6.3f `br'
	local sr = round(`r(sd)'*1000)/1000
	local sr : di  %6.3f `sr'

	sum q`y'_pro if recruit==1
	local bd = round(`r(mean)'*1000)/1000
	local bd : di %6.3f `bd'
	local sd = round(`r(sd)'*1000)/1000
	local sd : di  %6.3f `sd'
	
	local vlab1: variable label q`y'_pro

	file write fh ///
	"`vlab1' & `br'	& (`sr')  & & `bd'	& (`sd') 	\\" _n ///
	"[.1em]" _n	
		
}

count if recruit==0
local rN=r(N)
count if recruit==1
local dN=r(N)

file write fh ///
"&	&	& &	&	\\" _n ///
"N	&	`rN'	&	& &	`dN' & \\" _n ///
"[.25em]" _n ///
"\bottomrule" _n ///
"\end{tabular}}\hspace*{-1cm}" _n
file close fh




